// File Name: oled_task.c
// Author: kukukukuku~
// Date: 2024-12-23

#include "stdio.h"
#include "string.h"
#include "./OLED/inc/oled_font.h"
#include "./OLED/inc/oled_task.h"
#include "./RS485/inc/rs485_var.h"
#include "./USART/inc/usart_var.h"

//OLED任务句柄
TaskHandle_t oledTaskHandle;

/**
 * @brief   OLED任务
 * @param   arg:    任务参数
 * @retval  None
 * @note    None
*/
void oled_task(void *arg)
{
    static uint8_t str[10];
    
    vTaskDelay(200);
    
    taskENTER_CRITICAL();
    
    oled_code_init();
    oled_clear();
    
    taskEXIT_CRITICAL();
    
    oled_show_str_8x16(0, 0, oledFontSourceCodePro8x16, sizeof(oledFontSourceCodePro8x16), (uint8_t *)"R->U:", 0);
    oled_show_str_8x16(0, 2, oledFontSourceCodePro8x16, sizeof(oledFontSourceCodePro8x16), (uint8_t *)"U->R:", 0);
    
    oledRefreshFlag = 1;
    
    while(1)
    {
        if(oledRefreshFlag)
        {
            memset(str, 0, sizeof(str));
            sprintf((char *)str, "%-5u", rs485ToUsartCnt);
            oled_show_str_8x16(40, 0, oledFontSourceCodePro8x16, sizeof(oledFontSourceCodePro8x16), str, 0);
            
            memset(str, 0, sizeof(str));
            sprintf((char *)str, "%-5u", usartToRs485Cnt);
            oled_show_str_8x16(40, 2, oledFontSourceCodePro8x16, sizeof(oledFontSourceCodePro8x16), str, 0);
            
            oledRefreshFlag = 0;
        }
        
        vTaskDelay(10);
    }
}
